#include "SqliteHelper.hpp"
#include <vector>
#include <assert.h>


int selectCallback(void* arg, int colNum, char** result, char** feildName)
{
    std::vector<std::string>* pArray = (std::vector<std::string>*)arg;
    pArray->push_back(result[0]);
    return 0;   
}
int main()
{
    // 创建/打开库文件
    // 创建表：学生信息（学号、姓名、年龄）
    // 新增、删除、查找、修改
    // 关闭数据库
    SqliteHelper helper("./testDB");
    assert(helper.open());
    
    // const char* ctb = "create table if not exists Students(sn int primary key, name varchar(32), age int);";
    // assert(helper.exec(ctb, nullptr, nullptr));
    
    // const char* insert_sql = "insert into Students values(1, '小明', 16), (2, '张三', 17), (3, '李四', 16);";
    // assert(helper.exec(insert_sql, nullptr, nullptr));

    // const char* update_sql = "update Students set name = '大明' where sn = 1;";
    // assert(helper.exec(update_sql, nullptr, nullptr));

    // const char* delete_sql = "delete from Students where sn = 1;";
    // assert(helper.exec(delete_sql, nullptr, nullptr));

    const char* select_sql = "select name from Students;";
    std::vector<std::string> array;
    assert(helper.exec(select_sql, selectCallback, &array));
    for(auto& name :array)
    {
        std::cout << name << std::endl;
    }
    helper.close();
    return 0;
} 